import type { InjectionKey, Ref } from "vue";
import type { Condition } from "./ConditionPanel/types";
import type { PipeComposeItem } from "/@/components/PipePath/usePipePath";
import type {
  ConfigurationInstanceObj,
  Connection,
  FlowPathType,
  PipePathType,
  SelectEvent,
} from "/@/components/types";

export enum ConfigurationMode {
  //编辑器模式
  Editor,
  //应用模式
  Apply,
}

/**
 * common types
 */
export enum ConfigurationType {
  PipePath = "PipePath",
  DeviceImage = "DeviceImage",
  DeviceSvg = "DeviceSvg",
  LabelValue = "LabelValue",
  FlowPath = "FlowPath",
}
export interface SvgInfo {
  width: number;
  height: number;
  element: HTMLElement;
  container: HTMLDivElement;
}
export interface ConfigurationEl {
  id: string;
  //起始位置的中点
  centerX: number;
  centerY: number;
  //svg设备的svg组件名字
  componentName?: string;
  //初始化宽度
  initWidth?: number;
  initHeight?: number;
  //图片设备的图片路径
  imgSrc?: string;
  //图片设备的名字
  imgName?: string;
  //各种颜色
  colors?: string[];
  //文字组件
  initLabelX?: number;
  initLabelY?: number;
  //管道路径
  pipePathType?: PipePathType;
  flowPathType?: FlowPathType;
}
export interface RootCommon {
  cid: string;
  //compData
  deviceSvgData: Ref<ConfigurationEl[]>;
  deviceImageData: Ref<ConfigurationEl[]>;
  pipePathData: Ref<ConfigurationEl[]>;
  labelValueData: Ref<ConfigurationEl[]>;
  flowPathData: Ref<ConfigurationEl[]>;
  //legendData
  pipePathLegendData: Ref<PipePathLegend[]>;
  deviceImageLegendData: Ref<DeviceImageLegend[]>;
  deviceSvgLegendData: Ref<DeviceSvgLegend[]>;
  flowPathLegendData: Ref<FlowPathLegend[]>;
  //other
  compInstance: ConfigurationInstanceObj;
  connection: Connection;
  scaleFactor: Ref<number>;
  svgWidth: Ref<number>;
  svgHeight: Ref<number>;
  previewScale: Ref<number>;
  previewScaleChange: Ref<() => void>;
  selectItem: (e: SelectEvent) => void;
}
export const RootCommonKey: InjectionKey<RootCommon> = Symbol();

export interface ContextmenuItem {
  name?: string;
  handler?: () => void;
  showSubMenu?: boolean;
  split?: boolean;
  children?: ContextmenuItem[];
}
/**
 * legend types
 */
export interface DeviceSvgLegend {
  name: string;
  comp: any;
  width: number;
}

export interface PipePathLegend {
  type: PipePathType;
  colors: string[];
  outerOpacity?: number;
  composeData?: PipeComposeItem[];
}

export interface DeviceImageLegend {
  src: string;
  name: string;
}

export interface FlowPathLegend {
  type: FlowPathType;
}

/**
 * other
 */
export interface GridLineExpose {
  getEl: () => SVGGElement;
}
export interface BoxSelect {
  x: number;
  y: number;
  width: number;
  height: number;
}

export interface ConditionalPanelExpose {
  refresh: () => void;
}

export interface ConfigurationExpose {
  getCompConditionInfo: () => { [key: string]: Condition[] };
  getLabelValueKeys: () => string[];
}

export interface MainSvgExpose {
  initViewBox: () => void;
}

export interface PreviewDragBounding {
  minLeft: number;
  maxLeft: number;
  minTop: number;
  maxTop: number;
}
